/**
 * @a https://leetcode.cn/problems/find-largest-value-in-each-tree-row/description/
 */


#include "common.h"

//Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
        vector<int> ret;
        if(root == nullptr) return ret;
        queue<TreeNode*> que;
        que.push(root);
        while(que.size()){
            int sz = que.size();
            int tmp = -1e9;
            while(sz--){
                TreeNode* t = que.front();
                que.pop();
                tmp = max(tmp, t->val);
                if(t->left) que.push(t->left);
                if(t->right) que.push(t->right);
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};